package zsc.ruanc.practicaltraining.config;


import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 消息中间键配置
 */
@Configuration
public class RabbitMQConfig {

    /**
     * 序列化为json格式
     * @return
     */
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    /**
     * 定义交换器
     * @return
     */
    @Bean
    public Exchange fanout_exchange() {
        return ExchangeBuilder.directExchange("fanout_blog").build();
    }

    /**
     * 邮件队列
     * @return
     */
    @Bean
    public Queue fanout_queue_email() {
        return new Queue("fanout_queue_email");
    }

    @Bean
    public Binding bindingEmail() {
        return BindingBuilder.bind(fanout_queue_email()).to(fanout_exchange()).with("email").noargs();
    }

    /**
     * 系统通知队列
     */
    @Bean
    public Queue fanout_queue_info() {
        return new Queue("fanout_queue_info");
    }

    @Bean
    public Binding bindingInfo() {
        return BindingBuilder.bind(fanout_queue_info()).to(fanout_exchange()).with("info").noargs();
    }
}
